//
// Created by root on 19-10-17.
//

#ifndef OPENGLESPRO_GAME_STEP_2_H
#define OPENGLESPRO_GAME_STEP_2_H

#define VERTEX_ATTR_INDEX_V2_POSITION 0
#define VERTEX_ATTR_INDEX_V2_COLOR 1
#define VERTEX_VEC_COUNT_V2_PER_POSITION 2
#define VERTEX_VEC_COUNT_V2_PER_COLOR 4
// 每个顶点对应的分量个数，这里每个顶点用平面坐标(x,y)加上颜色(r,g,b,a)来表示，故共6个分量
#define VERTEX_VEC_COUNT_V2_PER_TOTAL (VERTEX_VEC_COUNT_V2_PER_POSITION+VERTEX_VEC_COUNT_V2_PER_COLOR)
// 跨距，告诉每个位置之间有多少个字节
#define STRIDE_BYTES_V2 VERTEX_VEC_COUNT_V2_PER_TOTAL*sizeof(GLfloat)

void OnSurfaceCreatedV2();

void OnSurfaceCreatedV2() {}

void OnSurfaceChangedV2();

void OnSurfaceChangedV2() {}

void OnDrawFrameV2();

void OnDrawFrameV2() {
    GLfloat vertexPointers[] = {
            // Order of coordinates: X, Y, R, G, B, A

            // Triangle Fan
            0, 0, 1, 1, 1, 1,
            -0.5, -0.5, 0.7, 0.7, 0.7, 1,
            0.5, -0.5, 0.7, 0.7, 0.7, 1,
            0.5, 0.5, 0.7, 0.7, 0.7, 1,
            -0.5, 0.5, 0.7, 0.7, 0.7, 1,
            -0.5, -0.5, 0.7, 0.7, 0.7, 1,

            // Line
            -0.5, 0, 1, 0, 0, 1,
            0.5, 0, 0, 1, 0, 1,

            // Mallets
            0, -0.25, 0, 0, 1, 1,
            0, 0.25, 1, 0, 0, 1
    };
    glVertexAttribPointer(VERTEX_ATTR_INDEX_V2_POSITION, VERTEX_VEC_COUNT_V2_PER_POSITION, GL_FLOAT,
                          GL_FALSE, STRIDE_BYTES_V2, &vertexPointers[0]);
    glEnableVertexAttribArray(VERTEX_ATTR_INDEX_V2_POSITION);
    glEnableVertexAttribArray(VERTEX_ATTR_INDEX_V2_COLOR);
    glVertexAttribPointer(VERTEX_ATTR_INDEX_V2_COLOR, VERTEX_VEC_COUNT_V2_PER_COLOR, GL_FLOAT,
                          GL_FALSE, STRIDE_BYTES_V2, &vertexPointers[2]);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 6); // 绘制矩形桌面，矩形桌面由前6个点组成
    glLineWidth(3);
    glDrawArrays(GL_LINES, 6, 2); // 绘制中间分割线，分割线由第7和第8两个点连接而成
    glDrawArrays(GL_POINTS, 8, 1); // 绘制第9个点，单独一个点
    glDrawArrays(GL_POINTS, 9, 1); // 绘制第10个点，单独一个点
}

#endif //OPENGLESPRO_GAME_STEP_2_H
